package ru.spbau.database.group3.parser;

/**
 * Created with IntelliJ IDEA.
 * User: stas
 * Date: 1/31/13
 * Time: 8:32 PM
 */
public enum ConditionOperator {

    LT("<") {
        @Override
        public boolean checkComparison(int c) {
            return c < 0;
        }
    },
    GT(">") {
        @Override
        public boolean checkComparison(int c) {
            return c > 0;
        }
    },
    E("=") {
        @Override
        public boolean checkComparison(int c) {
            return c == 0;
        }
    },
    LEQ("<=") {
        @Override
        public boolean checkComparison(int c) {
            return c <= 0;
        }
    },
    GEQ(">=") {
        @Override
        public boolean checkComparison(int c) {
            return c >= 0;
        }
    },
    NEQ("<>") {
        @Override
        public boolean checkComparison(int c) {
            return c != 0;
        }
    },
    EMPTY("") {
        @Override
        public boolean checkComparison(int c) {
            return true;
        }
    };

    public abstract boolean checkComparison(int c);


    public static ConditionOperator createConstraintOperator(String str) {
        for(ConditionOperator co : ConditionOperator.values()) {
            if(str.equals(co.representation)) {
                return co;
            }
        }
        throw new IllegalArgumentException("Wrong Constraint " + str);
    }

    private ConditionOperator(String representation) {
        this.representation = representation;
    }

    @Override
    public String toString() {
        return "ConditionOperator{" +
                "representation='" + representation + '\'' +
                '}';
    }

    private final String representation;
}
